<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8"/>
	<title>Document</title>
</head>
<body>
	<script>
		function *foo() {
			// body...
			var x=yield  2;
			z++;
			var y=yield (x*z);
			console.log(x,y,z)
		}
		var z=1;
		var it1=foo();
		var it2=foo();
		var val1=it1.next().value; //2
		var val2=it2.next().value; //2
		val1=it1.next(val2*10).value;// z=2 x=20 val1=40
		val2=it2.next(val1*5).value;//  z=3 x=200 val2=600
		it1.next(val2/2) // x=20  y=300 z=3
		it2.next(val1/4)// x=200  y=10 z=3

		var a=1;var b=2;
		function *bar() {
			// body...
			console.log('asdasd')
			yield;
			b=b*a;
			a= (yield b) + 3
		}
		var step=function(gen){
			var last;
			var it=gen()
			return function(){
				last=it.next(last).value
			}
		}
		var b1=step(bar)

		b1()
		b1()
		b1()
		console.log(a,b)
		function *count(){
			console.log('count')
			try{
				var nextval;
				while(true){
					if(nextval===undefined){
						nextval=1
					}else{
						nextval=(3*nextval)+6
					}
					yield nextval
				}
			}
			finally{
				console.log('end---end')
			}
		}
		var it=count()
		for(var i of it){
			console.log(i)
			if(i>500){
				console.log(it.return('hello').value)
				
			}
			
		}

		var something=(function(){
			var nextval;
			return {
				[Symbol.iterator]:function(){
					return this;
				},
				next:function(){
					if(nextval===undefined){
						nextval=1;
					}else{
						nextval=(3*nextval)+6
					}
					return {done:false,value:nextval}
				}
			}
		})()
		// something.next().value;
var foo = function *() {
  var x = 1;
  var y =  yield (x + 1) * 2;
  var z = yield x + y;
  return z;
}()
var a = foo.next();
var b = foo.next(3);
var c = foo.next(4);
console.log(a.value)
	</script>
</body>
</html>
